package org.liveboardgames.agricola.business.action.processor;

import java.util.List;

import org.liveboardgames.agricola.domain.Change;
import org.liveboardgames.agricola.domain.Game;
import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.model.enums.ActionOutputEnum;
import org.liveboardgames.agricola.utils.Enums;

public class ActionProcessorFactory {

  public static ActionProcessor getProcessor(Game game, String outputType, int outputQuantity, Action action,
      List<Change> changes) {
    ActionProcessor processor = null;

    String resourceType = Enums.convertActionOutputToResource(outputType);
    if (resourceType != null) {
      processor = new ResourceActionProcessor(game, action, changes, resourceType, outputQuantity);
    }
    else if (ActionOutputEnum.TAKE_ALL.equals(outputType)) {
      processor = new TakeAllActionProcessor(game, action, changes);
    }
    // else if (outputType == ActionOutputEnum.CHOICE_RESOURCE) {
    // processor = new ChooseBuildingMaterialActionProcessor(action);
    // }
    else if (ActionOutputEnum.FIRST_PLAYER.equals(outputType)) {
      processor = new FirstPlayerActionProcessor(game, action, changes);
    }
    // else if (outputType == ActionOutputEnum.PLOUGH) {
    // processor = new PloughActionProcessor(action);
    // }
    // else if (outputType == ActionOutputEnum.WOODEN_ROOM || outputType ==
    // ActionOutputEnum.CLAY_ROOM ||
    // outputType == ActionOutputEnum.STONE_ROOM) {
    // processor = new RoomActionProcessor(action);
    // }
    // else if (outputType == ActionOutputEnum.STABLE) {
    // processor = new StableActionProcessor(action);
    // }
    // else if (outputType == ActionOutputEnum.MAJOR_IMPROVEMENT) {
    // processor = new BuildMajorImprovementActionProcessor(action);
    // }
    else if (ActionOutputEnum.ADD_RESOURCE_ON_BOARD.equals(outputType)) {
      processor = new AddResourceOnBoardActionProcessor(game, action, changes);
    }
    else if (ActionOutputEnum.TAKE_RESOURCE_FROM_BOARD.equals(outputType)) {
      processor = new TakeResourceFromBoardActionProcessor(game, action, changes);
    }
    // else if (outputType == ActionOutputEnum.SOW) {
    // processor = new SowActionProcessor(action);
    // }
    // else if (outputType == ActionOutputEnum.TAKE_ANIMAL) {
    // processor = new AnimalActionProcessor(action);
    // }
    // else if (outputType == ActionOutputEnum.PASTURE) {
    // processor = new FencesActionProcessor(action);
    // }
    else if (ActionOutputEnum.RENOVATION_TO_CLAY.equals(outputType) ||
        ActionOutputEnum.RENOVATION_TO_STONE.equals(outputType)) {
      processor = new RenovationActionProcessor(game, action, changes);
    }
    else if (ActionOutputEnum.BIRTH.equals(outputType)) {
      processor = new BirthActionProcessor(game, action, changes);
    }
    else {
      throw new IllegalArgumentException("No processor for action type " + outputType);
    }

    return processor;
  }
}
